<include file="public@header"/>
</head>
<body>
<div class="wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('index')}">{:lang('商品列表')}</a></li>
        <li class="active"><a href="#">{:lang('编辑商品')}</a></li>
    </ul>
    <div id="moban" style="display: none">
         <span class="banner_span">
             <img src="{preview_url}" style="width: 150px; height: 100px;">
             <input type="hidden" name="banner[]" value="{filepath}">
             <i class="glyphicon glyphicon-trash del"></i>
         </span>
    </div>
    <style>
        .banner_span {
            position: relative;
            display: inline-block;
            overflow: hidden;
        }

        .banner_span .del {
            position: absolute;
            top: 33%;
            right: -30px;
            color: black;
            background: #EEEEEE;
            border: 1px solid #e8ffb2;
            padding: 5px;
            cursor: pointer;
            opacity: .8;
            transition: all 0.2s;
        }

        .banner_span:hover .del {
            right: 38%;
        }
    </style>
    <script src="https://cdn.bootcss.com/layer/2.3/layer.js"></script>
    <script>
        $(function () {
            $('#banner_wrap').on('click', '.banner_span .del', function () {
                that = $(this);
                layer.confirm('确定删除?', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    that.parents('.banner_span').remove();
                    layer.msg('已经删除', {icon: 1});
                });
            });
            $('#banner_wrap').on('click', 'img', function () {
                imagePreviewDialog($(this).attr('src'));
            })
        })
    </script>
    <form method="post" class="form-horizontal margin-top-20 js-ajax-form" action="{:url('editPost')}">
        <div class="form-group">
            <label for="cid" class="col-sm-2 control-label"><span class="form-required">*</span>所属分类</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control" name="cid" id="cid">
                    {$select_category}
                </select>
            </div>
        </div>

        <div class="form-group">
            <label for="title" class="col-sm-2 control-label"><span class="form-required">*</span>商品标题</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" id="title" name="title" value="{$data.title}">
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>商品封面</label>
            <div class="col-md-6 col-sm-10">

                <div>
                    <input type="hidden" name="img" id="thumb" value="{$data.img}">
                    <a href="javascript:uploadOneImage('图片上传','#thumb');">
                        <img src="
                        <empty name=" $data['img']">
                        /themes/admin_simpleboot3/public/assets/images/default-thumbnail.png
                        <else/>
                        {:cmf_get_image_url($data['img'])}
                        </empty>
                        " id="thumb-preview"
                        style="cursor: hand;width: 150px; height: 150px;">
                    </a>
                    <input type="button" class="btn btn-sm"
                           onclick="$('#thumb-preview').attr('src','/themes/admin_simpleboot3/public/assets/images/default-thumbnail.png');$('#thumb').val('');return false;"
                           value="取消图片">
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>轮播图</label>
            <div class="col-md-6 col-sm-10">
                <span id="banner_wrap">
                    <foreach name="$data['banner']" item="banner">
                        <span class="banner_span">
                            <img src="{:cmf_get_image_url($banner)}" style="width: 150px; height: 100px;">
                            <input type="hidden" name="banner[]" value="{$banner}">
                            <i class="glyphicon glyphicon-trash del"></i>
                        </span>
                    </foreach>
                </span>
                <a href="javascript:uploadMultiImage('banner图片上传','#banner_wrap','moban');">上传</a>
            </div>
        </div>

        <div class="form-group">
            <label for="showprice" class="col-sm-2 control-label"><span class="form-required">*</span>展示价格</label>
            <div class="col-md-6 col-sm-10">
                <input type="number" class="form-control" id="showprice" name="showprice" value="{$data.showprice}">
            </div>
            元
        </div>

        <div class="form-group">
            <label for="token_money" class="col-sm-2 control-label"><span class="form-required">*</span>可使用代币数</label>
            <div class="col-md-6 col-sm-10">
                <input type="number" class="form-control" id="token_money" name="token_money"
                       value="{$data.token_money}">
            </div>
            个
        </div>


        <div class="form-group">
            <label for="postage" class="col-sm-2 control-label"><span class="form-required">*</span>邮费</label>
            <div class="col-md-6 col-sm-10">
                <input type="number" class="form-control" id="postage" name="postage" value="{$data.postage}">
            </div>
            元
        </div>


        <script src="https://cdn.bootcss.com/distpicker/2.0.5/distpicker.min.js"></script>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>发货地</label>
            <div class="col-md-6 col-sm-10">
                <div data-toggle="distpicker">
                    <div class="col-md-6">
                        <select class="form-control" name="address_p" data-province="{$data.address_p}"></select>
                    </div>
                    <div class="col-md-6">
                        <select class="form-control" name="address_c" data-city="{$data.address_c}"></select>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>是否上架</label>
            <div class="col-md-6 col-sm-10">
                <select name="status" class="form-control">
                    <switch name="$data.status">
                        <case value="1">
                            <option value="1" selected>上架</option>
                            <option value="0">下架</option>
                        </case>
                        <case value="0">
                            <option value="1">上架</option>
                            <option value="0" selected>下架</option>
                        </case>
                    </switch>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>是否推荐</label>
            <div class="col-md-6 col-sm-10">
                <select name="is_tuijian" class="form-control">
                    <switch name="$data.is_tuijian">
                        <case value="1">
                            <option value="1" selected>是</option>
                            <option value="0">否</option>
                        </case>
                        <case value="0">
                            <option value="1">是</option>
                            <option value="0" selected>否</option>
                        </case>
                    </switch>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>商品类型</label>
            <div class="col-md-6 col-sm-10">
                <select class="form-control" name="spec_type_id" id="spec_type_id">
                    <option value="">请选择</option>
                    <volist name="spec_type_list" id="vo">
                        <option value="{$vo.id}"
                        <eq name="$data.spec_type_id" value="$vo.id">selected</eq>
                        >{$vo.name}</option>
                    </volist>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>规格</label>
            <div class="col-sm-6" id="goods_spec_values"></div>
        </div>

        <div class="form-group" id="oneKey">
            <label class="col-sm-2 control-label">批量设置</label>
            <div class="col-sm-6">
                <div class="row">
                    <div class="col-sm-6">
                        <div class="input-group">
                          <span class="input-group-btn">
                            <span class="btn btn-default" disabled>库存设置</span>
                          </span>
                            <input type="number" id="batch_stock" class="form-control">
                            <div class="input-group-btn">
                                <button type="button" id="btn_batch_stock" class="btn btn-danger form-control">设置
                                </button>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="input-group">
                          <span class="input-group-btn">
                            <span class="btn btn-default" disabled>价格设置</span>
                          </span>
                            <input type="number" id="batch_price" class="form-control">
                            <div class="input-group-btn">
                                <button type="button" id="btn_batch_price" class="btn btn-danger form-control">设置
                                </button>
                            </div>

                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>商品详情</label>
            <div class="col-md-6 col-sm-10">
                <script type="text/javascript" charset="utf-8"
                        src="/static/js/ueditor/ueditor.config.js"></script>
                <script type="text/javascript" charset="utf-8"
                        src="/static/js/ueditor/ueditor.all.min.js"></script>
                <script name="content" id="editor" type="text/plain" style="width:100%;height:300px;"></script>
                <script >
                var ue = UE.getEditor('editor');
                ue.ready(function () {
                    ue.setContent('{$data.content}');
                });
                </script>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" name="id" value="{$data.id}">
                <button type="submit" class="btn btn-info js-ajax-submit" onclick="return confirm('确认提交吗?')">
                    {:lang('ADD')}
                </button>
            </div>
        </div>
    </form>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script type="text/javascript">
    $(function () {
        //初始化商品类型
        var goods_id = '{$data.id}';
        var spec_type_id = '{$data.spec_type_id}';
        specType(spec_type_id, goods_id);
        //商品类型选择
        $("#spec_type_id").on("change", function () {
            var spec_type_id = $(this).val();
            specType(spec_type_id, 0);
            if (spec_type_id == '') {
                $('#oneKey').hide();
                $('#spec').hide();
            } else {
                $('#oneKey').show();
                $('#spec').show();
            }
        });

        function specType(spec_type_id, goods_id) {
            $.post("{:url('GoodsSpec/getSpecListTable')}", {"category_id": spec_type_id, goods_id}, function (result) {
                if (result.code == 200) {
                    $("#goods_spec_values").html(result.data);
                } else {
                    alert("获取规格数据错误");
                }
            }, 'json');
        }

        //批量填充价格
        $("#btn_batch_stock").on("click", function () {
            var batch_stock = $("#batch_stock").val();
            $(".spec_stock").val(batch_stock);
        });
        $("#btn_batch_price").on("click", function () {
            var batch_price = $("#batch_price").val();
            $(".spec_price").val(batch_price);
        });
    });
</script>

</body>
</html>